//
//  HMAccount.m
//  Gegeda_music_MY
//
//  Created by lanou3g on 15/11/5.
//  Copyright © 2015年 周莹. All rights reserved.
//

#import "HMAccount.h"

@implementation HMAccount
+(instancetype)accountWithDict:(NSDictionary *)dict{
    HMAccount *account = [[self alloc] init ];
    account.access_token = dict[@"access_token"];
    account.expires_in = dict[@"expires_in"];
    account.uid = dict[@"uid"];
    //确定账号的过期时间:账号创建时间+有效期
    NSDate  *now = [NSDate  date ];
    account.expires_time = [now  dateByAddingTimeInterval:account.expires_in.doubleValue];
    

    return account;

}
//当从文件中解析出一个对象的时候调用
// 在这个方法中写清楚：怎么解析文件中的数据
- (id)initWithCoder:(NSCoder *)decoder{
    if (self = [super init]) {
        self.access_token = [decoder  decodeObjectForKey:@"access_token"];
        self.expires_in = [decoder   decodeObjectForKey:@"expires_in"];
        
        self.uid = [decoder decodeObjectForKey:@"uid"];
        self.expires_time = [decoder   decodeObjectForKey:@"expires_time"];
        
            }
    return self;


}

//将对象写入文件的时候调用
//在这个方法中写清楚：要存储哪些对象的哪些属性，以及怎样存储属性

-(void)encodeWithCoder:(NSCoder *)aCoder{
    [aCoder  encodeObject:self.access_token forKey:@"access_token"];
    
    [aCoder  encodeObject:self.expires_in forKey:@"expires_in"];
    
    [aCoder  encodeObject:self.expires_time forKey:@"expires_time"];
    
    [aCoder  encodeObject:self.uid forKey:@"uid"];
    

}











@end
